package com.jy.rhin.facade.infra.controller.node;

import com.jy.framework.base.entity.Result;
import com.jy.rhin.domain.document.node.NodeAuthenticationPermissionService;
import com.jy.rhin.sdk.dto.node.NodeAuthenticationPermissionModuleDto;
import com.jy.rhin.sdk.dto.node.NodeAuthenticationPermissionRelationDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@RestController
@RequestMapping("/infra/node/authentication/permission")
@Api(tags = "节点认证权限api")
@Slf4j
public class NodeAuthenticationPermissionController {

    @Autowired
    private NodeAuthenticationPermissionService nodeAuthenticationPermissionService;


    @ApiOperation(value = "节点认证权限查询", notes = "节点认证权限查询")
    @GetMapping("/getNodePermissionList")
    public Result<List<NodeAuthenticationPermissionModuleDto>> getNodePermissionList() {
        return  Result.success(nodeAuthenticationPermissionService.getNodePermissionList());
    }


    @ApiOperation(value = "保存节点权限关系", notes = "保存节点权限关系")
    @PostMapping("/saveNodePermissionRelation")
    public Result saveNodePermissionRelation(@RequestBody List<NodeAuthenticationPermissionRelationDto> nodeAuthenticationPermissionRelationDtoList) {
        nodeAuthenticationPermissionService.saveNodePermissionRelation(nodeAuthenticationPermissionRelationDtoList);
        return  Result.success();
    }
    
    @ApiOperation(value = "接口权限认证", notes = "节点认证权限查询")
    @GetMapping("/hasPermission")
    public Result<Boolean> hasPermission(@RequestParam("publicKey")String publicKey,@RequestParam("action")String action) {
        return  Result.success(nodeAuthenticationPermissionService.hasPermission(publicKey, action));
    }

}
